//
//  SINATecMainItemTableViewCell.m
//  sinashebao
//
//  Created by  androidlongs on 2018/3/15.
//  Copyright © 2018年  androidlongs. All rights reserved.
//

#import "SINATecMainItemAlertTimeTableViewCell.h"
#import "SINACircularBeadUtils.h"
#import "SINACalendarUtils.h"


@interface SINATecMainItemAlertTimeTableViewCell ()
@property (weak, nonatomic) IBOutlet UIView *mainView;
//时间选项
@property (weak, nonatomic) IBOutlet UILabel *timeAlertLabel;
//结束
@property (weak, nonatomic) IBOutlet UILabel *closeAlertLabel;

@end
@implementation SINATecMainItemAlertTimeTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
    
    [SINACircularBeadUtils makeCircularBead:2 andView:self.mainView];
    
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

-(void)setModel:(SINASubClassModel *)model{
    _model = model;
    
    
    
    if (self.itemBlock) {
        [[SINAUiviewClickLiserner alloc]viewClickFunction:self.contentView andWithBlick:^(UIView *view) {
            if (model.itemType==1) {
                self.itemBlock(self.model,0);
            }else if (model.itemType==2){
                self.itemBlock(self.model,1);
            }else{
                self.itemBlock(self.model,2);
            }
        }];
    }
    if (model.itemType==1) {
        
        self.timeAlertLabel.text=[NSString stringWithFormat:@"%@ - %@",[SINACalendarUtils getDateStringWithTimeStr:model.starttime andFormat:@"MM月dd日 HH:mm"],[SINACalendarUtils getDateStringWithTimeStr:model.endtime andFormat:@"HH:mm"]];;
        
        self.closeAlertLabel.hidden = YES;
        self.timeAlertLabel.hidden = NO;
        self.mainView.backgroundColor =[UIColor whiteColor];
        if (model.ishas==0) {
            //无课
            self.mainView.backgroundColor=[UIColor whiteColor];
        } else {
            self.mainView.backgroundColor=[UIColor colorWithHexString:@"#f7f7f7"];
        }
        
        //当前课程的开始时间
        NSInteger courStartTime = [self.alertCourseModel.starttime integerValue];
        //当前时间的结束时间
//        NSInteger courEndTime = [self.alertCourseModel.endtime integerValue];
        //当前Item显示的时间
        NSInteger currentStartTime = [self.model.starttime integerValue];
//        NSInteger currentEndTime = [self.model.endtime integerValue];
        
        if (courStartTime<currentStartTime) {
            //可调课
            if (model.ishas==0) {
                //无课
                self.mainView.backgroundColor=[UIColor whiteColor];
            } else {
                //有课
                self.mainView.backgroundColor=[UIColor colorWithHexString:@"#f7f7f7"];
            }
        } else {
            NSInteger currentTime = [[SINACalendarUtils currentTimeStr] integerValue];
            if (currentTime<currentStartTime) {
                //后天的课调整到昨天
                if (model.ishas==0) {
                    //无课
                    self.mainView.backgroundColor=[UIColor whiteColor];
                } else {
                    //有课
                    self.mainView.backgroundColor=[UIColor colorWithHexString:@"#f7f7f7"];
                }
            }else if(courStartTime==currentStartTime){
                 self.mainView.backgroundColor=[UIColor colorWithHexString:@"#f7f7f7"];
            }else{
                //不可调课
                self.mainView.backgroundColor=[UIColor colorWithHexString:@"#f7f7f7"];
            }
            
        }
        
    }else if (model.itemType==3) {
        self.closeAlertLabel.hidden = YES;
        self.timeAlertLabel.hidden = NO;
        self.timeAlertLabel.text=@"暂无调用时间";
        self.mainView.backgroundColor =[UIColor whiteColor];
    } else {
        self.closeAlertLabel.hidden = NO;
        self.timeAlertLabel.hidden = YES;
        self.mainView.backgroundColor = baseSelectColor;
    }
    
    
}


@end
